-
Notifications
You must be signed in to change notification settings - Fork 365
Consider embedded properties in the QBE queries #2100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off the commits |
3d8fa6e
to
a7f08ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR goes into the right direction. There's quite some noise and parameter and variable names are quite lengthy. Long names add complexity and from my perspective, they do not improve readability or understandability by explaining different domains.
|
||
Object actualPropertyValue = entityPropertiesAccessor.getProperty(property); | ||
|
||
if (property.isEmbedded() && actualPropertyValue != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we don't distinguish based on whether the property is an embedded one but rather whether it is an entity. At some point it should be possible to express criteria based across objects that are part of the aggregate (like it is done in JPA, we consider embeddables and references).
.../main/java/org/springframework/data/relational/repository/query/RelationalExampleMapper.java
Outdated
Show resolved
Hide resolved
* @return query | ||
*/ | ||
private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntity<?> entity) { | ||
private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntity<?> persistentEntity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason behind the renaming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because one can confuse the PersistenceEntity
with the entity
as the actual instance/probe. I do not insist here at all, just my observation when working with code, what do you think, @mp911de ?
.../main/java/org/springframework/data/relational/repository/query/RelationalExampleMapper.java
Outdated
Show resolved
Hide resolved
) { | ||
final List<Criteria> criteriaBasedOnProperties = new ArrayList<>(); | ||
|
||
persistentEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) property -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use a for-loop instead of callback-style to reduce stack frames.
* @param criteriaBasedOnProperties collection of {@link Criteria} objects to potentially enrich. | ||
* @param currentPropertyPath the dot-separated path of the passed {@code property}. | ||
*/ | ||
private void processEmbeddedRecursively( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a duplication of the general code that collects criteria for example matching. Should be consolidated.
…rties in QBE Signed-off-by: mipo256 <[email protected]> Signed-off-by: Михаил Поливаха <[email protected]>
@mp911de Just to make sure that we're on the same page. The current version of the algorithm accounts for the deeply nested embedded objects, like:
The problem is that if we unroll the recursion into the for-loop, then the code may get a bit messy, since this is not a tail-recursive function we're dealing with. I've tinkered with it, and the only sensible approach I found is to flatten-out all the properties of all the embedded objects (included deeply embedded) on demand, and store them in some kind of I'm unsure that this is the best solution. From my personal, empirical data, I may humbly conclude that objects. Therefore the call stack will probably not be large at all. But again, this is merely my observation. Now, having said that, I can push the for-loop like approach with Queue and we'll have a look. WDYT, @mp911de, @schauder ? |
Closes #2099
Closes #1986
This PR enhances the
RelationalExampleMapper
by making it consider embedded properties and specifiers for them.As it turned out during resolution of #1986, the embedded properties were kind of ignored in QBE.
Current algorithm works more a less the same way, it just traverses the
Example
recursively from direct properties defined in the rootprobe
, all the way down to the deeply embedded leafs.Tests are included in the PR.
CC: @mp911de @schauder